﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Drawing;
using System.Drawing.Imaging;
using System.Net.Mail;
using System.Net;

namespace Archipel
{
    public partial class Contact : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string confirmText = RandomImageGeneator.RandomString(4,false);
            Bitmap confirmImage = RandomImageGeneator.Generate(confirmText);         
        }

        protected void btnSend_Click(object sender, EventArgs e)
        {
            string from = "guestcontact.archno6@gmail.com";
            string to = "guestcontact.archno6@gmail.com";   //must replace with kientrucso6@gmail.com
            string subject = this.txtSubject.Text.Trim();
            string body ="Name: " +  this.txtName.Text + "\nEmail: " + this.txtEmail.Text + "\nMessage: " + taMessage.Value.Trim();

            this.SendMail(from, to, subject, body);
        }

        private void SendMail(string from, string to, string subject, string body)
        {
            SmtpClient client = new SmtpClient("smtp.gmail.com", 587);  //host, port (port must be 587)
            client.EnableSsl = true;
            client.Credentials = new NetworkCredential("guestcontact.archno6@gmail.com", "arch1234");   //username, password
            MailMessage mail = new MailMessage();
            mail.From = new MailAddress(from);
            mail.To.Add(new MailAddress(to));
            mail.Subject = subject;
            mail.Body = body;
            client.Send(mail);
        }
    }
}
